﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Staff
{
    public partial class role_load_manager : System.Web.UI.Page
    {
        public int id;
        public string accept = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            id = int.Parse(Request.QueryString["id"]);
            var get_menu = new TblAdminMenuController().FetchAll().Where(x => x.AmId == id).Single();
            accept = get_menu.AmAccept;
        }
        public bool check_accept(int id, string role)
        {
            if(!String.IsNullOrEmpty(role))
            {
                string[] split = role.Split(',');
                for (int i = 0; i < split.Length - 1; i++)
                {
                    if (id == int.Parse(split[i]))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public bool check_full_acceot(int role,string accept)
        {
            bool check = true;
            string[] split = accept.Split(',');
            var get_manager = new TblManagerController().FetchAll().Where(x => x.Role == role && x.Active == true);
            foreach(TblManager manager in get_manager) {
                bool temp = false;
                for(int i=0;i<split.Length-1;i++)
                {
                    if (manager.ManagerId == int.Parse(split[i]))
                    {
                        temp = true;
                        break;
                    }
                    
                }
                if (temp == false)
                {
                    check = false;
                    break;
                }
            }
            return check;
        }
    }
}